<script lang="ts">
import { defineComponent,ref } from "vue";
import { showToast} from 'vant'
import { storeToRefs } from 'pinia';
import { useCounterStore } from '../stores/home'
import {playerTime } from "../hooks/filters"
import { useRouter } from "vue-router";
import { useRoute } from "vue-router";


export default defineComponent({
    setup() {
        let router: any = useRouter();
        let route: any = useRoute();
        // 分享组件
        const showShare = ref(false);
        const options= [
            { name: '微信', icon: 'wechat' },
            { name: '微博', icon: 'weibo' },
            { name: '复制链接', icon: 'link' },
            { name: '分享海报', icon: 'poster' },
            { name: '二维码', icon: 'qrcode' },
        ];
        const onSelect = (option:any) => {
            showToast(option.name);
            showShare.value = false;
        };

        // pinia 
        const store = useCounterStore()
        const { idarr, likearr, collectlikearr, num, tocked,userInfoheard } = storeToRefs(store);
        console.log("num222=>", num)
        // 作为 action 的 increment 可以直接解构
        const { changnum, increment, incrementfalse, unlikeFuns, likeFuns, uncommentFuns, commentFuns,getUserInfoFun} = store;


        // 从local中拉出
        let localmynotejson:any =window.localStorage.getItem("mynoteArr")
        let localmynote = JSON.parse(localmynotejson)
        let mynoteArr:any = ref(localmynote||[])

        // 点击头像跳路由
        let toOthersInfo: any = (id: any): any => {
            router.push({
                path: '/userdetail',
                query: {
                    userid: id
                }
            })
        }

        // 点击自己发的手记跳转
        let toMysendNote: any = (id: any) => {
            router.push({
                path: "/mysendnote",
                query: {
                    id: id
                }
            })
        }

        // 点击图片放大
        let mybigpic: any = ref(null)
        let isshow = ref(false)

        let pic = (index:any) => {
            mynoteArr.value[0].images.forEach((item: any, index1: any) => {

                if (index == index1) {
                    mybigpic.value = mynoteArr.value[0].images[index1]
                }
                console.log("mybigpic=>", mybigpic.value)
            })

        }





        return {
            options,
            onSelect,
            showShare,
            // pinia需要导出的
            idarr,
            likearr,
            collectlikearr,
            tocked,
            userInfoheard,
            changnum,
            increment,
            incrementfalse,
            unlikeFuns,
            likeFuns,
            uncommentFuns,
            commentFuns,
            getUserInfoFun,
            mynoteArr,
            playerTime,
            toOthersInfo,
            toMysendNote,
            pic,
            mybigpic,
            isshow,
            num
        }
    }

})



</script>

<template>
    <div class="myNote"> 
    <!-- 我的发送的手记内容 -->
    <div class="my-top">
        <span class="iconfont icon-xiangzuojiantou" @click="$router.back()"></span>
        <h3>我的手记</h3>
    </div>
    <div class="hande-content" v-for="(item, index) in mynoteArr  " :key="index">
        <!-- 用户头像 -->
        <div class="head-pic" v-if="userInfoheard">
            <!-- 点击头像跳转路由 -->
            <img :src="userInfoheard.avatar" @click="toOthersInfo(item.user.id)">
            <div class="user-box">
                <div class="user-name">
                    <p class="name">{{ userInfoheard.username }} <span class="iconfont icon-VIP1"></span> </p>
                    <p class="updata-time">{{ playerTime(item.addtime) }} 发布</p>
                </div>

                <div class="flow-box">
                    <span class="flow" v-if="!idarr.includes(item.user.id)" @click="increment(item.user.id)">
                        + 关注 </span>
                    <span class="flow" v-else @click="incrementfalse(item.user.id)"> 已关注 </span>
                    <!-- <span class="iconfont icon-Androidgengduo"></span> -->
                    <van-cell class="iconfont icon-Androidgengduo" @click="showShare = true" />
                </div>
            </div>
        </div>
        <!-- 手记描述 -->
        <div class="content-desc">
            <p class="desc-title" @click="toMysendNote(item.id)">{{ item.title == "" ? '转发了作品' : item.title }}
            </p>
            <p class="desc-worlds" @click="toMysendNote(item.id)">
                <span class="desc-tag" v-if="item.topics"> # {{ item.topics[0].name }} </span>
                {{ item.content }}
            </p>
            <!-- 图片 -->
            <div class="desc-img">
                <!-- 自己发手记的遮罩层级  -->
                <van-button class="img-boc" type="primary" v-for="(item1, index1) in item.images" :key="index1"
                    @click="isshow = true; pic(index1)">
                    <img :src="item1.content">
                </van-button>

                <van-overlay class="myoverlay" :show="isshow" @click="isshow = false">
                    <div class="wrapper" @click.stop>
                        <div class="block" @click="isshow = false">
                            <img :src="mybigpic.content">
                        </div>
                    </div>
                </van-overlay>
            </div>
        </div>
        <div class="hande-content-btn">
            <!-- 我发的手记的点赞数 -->
            <!-- <div class="hande-content-btns">
                            <p class="iconfont icon-dianzan1"> </p> <span> {{ item.count.count_liked }} </span>
                        </div> -->
            <div class="hande-content-btns" @click.stop="likeFuns(item.id)" v-if="!likearr.includes(item.id)">
                <p class="iconfont icon-dianzan"> </p> <span> {{ item.count.count_liked }} </span>
            </div>
            <div class="hande-content-btns" @click.stop="unlikeFuns(item.id)" v-else>
                <p class="iconfont icon-dianzan_kuai" style="color:red"> </p> <span> {{ item.count.count_liked +
                    1 }} </span>
            </div>

            <div class="hande-content-btns">
                <p class="iconfont icon-review"> </p> <span>{{ num }} </span>
            </div>
            <!-- <p class="iconfont icon-fenxiang3"> <span> {{item.count.count_shared}} </span> </p> -->

            <div class="hande-content-btns">
                <van-cell class="iconfont icon-fenxiang3" @click="showShare = true" /> <span>
                    {{ item.count.count_shared }} </span>
            </div>

            <van-share-sheet v-model:show="showShare" title="立即分享给好友" :options="options" @select="onSelect" />
        </div>
    </div>
</div>
</template>


<style lang="scss">
.myNote{
    background-color:#f3f3f5;
    .my-top{
    display: flex;
    width: 100%;
    height: 43px;
    align-items: center;
    padding-left: 16px;
    box-sizing: border-box;
    background-color: #ffffff;
    h3{
        margin-left: 118px;
        font-weight: 900;
    }
    span{
        font-weight: 900;
    }
}
        .hande-content {
            margin-top: 8px;
            background-color: #ffffff;
            padding-left: 16px;
            padding-top: 16px;
            padding-right: 16px;

            .head-pic {
                display: flex;

                img {
                    width: 40px;
                    height: 40px;
                    border-radius: 50%;
                    margin-right: 10px;
                }

                .user-box {
                    width: 90%;
                    display: flex;
                    justify-content: space-between;

                    .user-name {
                        .name {
                            // font-weight: bold;
                            font-size: 14px;

                        }

                        .updata-time {
                            color: #b0b0b2;
                            font-size: 10px;
                            margin-top: 7px;
                        }

                        .icon-VIP1 {
                            color: #e73f29;
                        }

                    }

                    .flow-box {
                        display: flex;
                        width: 68px;
                        align-items: center;
                        font-weight: 600;

                        .flow {
                            color: #e54e44;
                            font-size: 12px;
                            display: block;
                            width: 112px;

                        }

                        .icon-Androidgengduo {
                            color: #888888;
                            margin-left: 10px;
                            padding: 0px;
                        }
                    }
                }

            }

            .content-desc {
                margin-top: 16px;
                border-bottom: 2px solid #fafafa;
                padding-bottom: 10px;

                .desc-title {
                    font-size: 16px;
                    font-weight: bold;
                }

                .desc-worlds {
                    margin-top: 8px;
                    font-size: 14px;
                    -webkit-line-clamp: 3;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    overflow: hidden;
                    text-overflow: ellipsis;

                    .desc-tag {
                        color: #4d73cb;
                        font-size: 14px;
                    }
                }

                .desc-img {
                    display: flex;
                    // justify-content: space-between;
                    margin-top: 16px;
                    flex-wrap: wrap;

                    .van-button--primary {
                        border: none;
                        outline: none;
                        background-color: #b0b0b2;

                        img {
                            width: 110px !important;
                            height: 110px !important;
                            border-radius: 5px;

                        }
                    }

                    .img-boc {
                        width: 110px;
                        height: 110px;
                        border-radius: 5px;

                        overflow: hidden;
                        margin-bottom: 5px;
                        margin-right: 6px;

                        img {
                            width: 100%;
                            height: 100%;
                        }

                        &:nth-of-type(3),
                        &:nth-of-type(6),
                        &:nth-of-type(9) {
                            margin-right: 0px;
                        }
                    }

                }

                .desc-video {
                    margin-top: 12px;
                    display: flex;

                    .video-pic {
                        width: 160px;
                        height: 92px;
                        border-radius: 5px 0px 0px 5px;
                        overflow: hidden;
                        position: relative;

                        img {
                            width: 100%;
                            height: 100%;
                        }

                        span {
                            position: absolute;
                            bottom: 10px;
                            color: #ffffff;
                            font-size: 11px;
                        }

                        .video-time {
                            right: 10px;
                        }

                        .icon-yanjing_xianshi_o {
                            left: 10px;
                        }

                        .icon-dianzan1 {
                            left: 60px;
                        }

                    }

                    .video-card {
                        width: 184px;
                        height: 92px;
                        border-radius: 0px 5px 5px 0px;
                        background-color: #f3f4f6;
                        padding: 14px;
                        box-sizing: border-box;

                        .video-name {
                            font-size: 13px;
                            -webkit-line-clamp: 2;
                            display: -webkit-box;
                            -webkit-box-orient: vertical;
                            overflow: hidden;
                            text-overflow: ellipsis;
                        }

                        .video-author {
                            margin-top: 12px;
                            color: #95969b;
                            font-size: 12px;
                        }
                    }
                }
            }

            .hande-content-btn {
            height: 41px;
            display: flex;
            align-items: center;
            justify-content: space-around;

            .hande-content-btns {
                display: flex;
                align-items: center;

                .van-cell {
                    padding: 0px;
                }
            }

            .icon-dianzan1,
            .icon-review,
            .icon-fenxiang3 {
                font-size: 17px;
                color: #605e6c;
            }

            span {
                font-size: 13px;
                color: #605e6c;
                margin-left: 5px;
            }

        }
  }
}

           
        

</style>